﻿
/*=========================================
* Author: Administrator
* DateTime:2017/6/21 18:17:11
* Description:$safeprojectname$
==========================================*/

using System;
using System.Collections.Generic;
using UnityEngine;
using PureMVC.Patterns;

namespace OrderSystem
{
   


    public class CookProxy : Proxy
    {   
        public CookView cookView = null;

        public void AddNewOrder(Order order)
        {
            makeFood(order);
        }

        public void modifyCookItemState(CookItem cookItem)
        {
            cookItem.state = E_CookState.Idle;
            cookItem.curOrder = null;
            SendNotification(OrderSystemEvent.UPDATE_COOKER_REST_STATE, Cooks);       
        }      
              
        public List<Order> delayOrders = new List<Order>();


        public void makeFood(Order order)
        {

            CookItem cooker = GetCook(this.Cooks);
            if(cooker!=null)
            {
                cooker.setOrder(order);
                cooker.state = E_CookState.MakeFood;
                SendNotification(OrderSystemEvent.UPDATE_COOK_WORK_STATE,Cooks);
            }
            else
            {
                Debug.Log("order传入makefood方法为空");
                delayOrders.Add(order);                
            }

        }

        public new const string NAME = "CookProxy";

        public IList<CookItem> Cooks
        {
            get { return (IList<CookItem>) base.Data; }
        }     
       

      
        public CookProxy( ) : base(NAME , new List<CookItem>())
        {
            AddCook(new CookItem(1 , "强尼",E_CookState.Idle));
            AddCook(new CookItem(2 , "托尼", E_CookState.Idle));
            AddCook(new CookItem(3 , "鲍比" , E_CookState.Idle));
            AddCook(new CookItem(4 , "缇米", E_CookState.Idle));
        }
        public void AddCook( CookItem item )
        {
            Cooks.Add(item);
        }
        public void RemoveCook( CookItem item )
        {
            Cooks.Remove(item);
        }

        public CookItem GetCook(IList<CookItem> Cooks)
        {
            CookItem item =null;
            for (int i = 0; i < Cooks.Count; i++)
            {
                if(Cooks[i].state.Equals(E_CookState.Idle))
                {
                    item = Cooks[i];
                    break;
                }
            }           
            return item;
        }

    }
}